package com.ftd.model;

import com.sun.tools.javac.util.List;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * Created by apple on 2016/12/7.
 */
@Component
public class User implements Serializable {
    private int userId;
    private String userPhone;
    private String userPassword;
    private String userEmail;
    private Date createTime;
    private Set<Book> books;

    public User() {

    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Set<Book> getBooks() {
        return books;
    }

    public void setBooks(Set<Book> books) {
        this.books = books;
    }

    public static class Builder{

        private int userId;
        private String userPhone = null;
        private String userPassword = null;
        private String userEmail = null;
        private Set<Book> books = null;

        public Builder(String userPhone,String userPassword,String userEmail){
            this.userPhone = userPhone;
            this.userPassword = userPassword;
            this.userEmail = userEmail;
        }

        public Builder books(Set<Book> list){
            this.books = list;
            return this;
        }

        public User bulid(){
            return new User(this);
        }

    }

    public User(Builder b){
        this.userPhone = b.userPhone;
        this.userPassword = b.userPassword;
        this.userEmail = b.userEmail;
        this.books = b.books;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (userId != user.userId) return false;
        if (userPhone != null ? !userPhone.equals(user.userPhone) : user.userPhone != null) return false;
        if (userPassword != null ? !userPassword.equals(user.userPassword) : user.userPassword != null) return false;
        if (userEmail != null ? !userEmail.equals(user.userEmail) : user.userEmail != null) return false;
        if (createTime != null ? !createTime.equals(user.createTime) : user.createTime != null) return false;
        return books != null ? books.equals(user.books) : user.books == null;

    }

    @Override
    public int hashCode() {
        int result = userId;
        result = 31 * result + (userPhone != null ? userPhone.hashCode() : 0);
        result = 31 * result + (userPassword != null ? userPassword.hashCode() : 0);
        result = 31 * result + (userEmail != null ? userEmail.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (books != null ? books.hashCode() : 0);
        return result;
    }
}
